<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>病案打印页面</title>
    <meta name="description" content="" />
    <link rel="stylesheet" href="${basePath}/static/print/css/print.css"/>
     <style media=print>
 	.Noprint{display:none;} 
 	.PageNext{page-break-after: always;}
 	.block{display:block;}
 </style>
 
</head>


 <OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 style="display:none">
 </OBJECT>
<body>
<div class="content clearfix">
	
	<input type="hidden" value="${medicalOnlyId}" id="medicalOnlyId"/>
	<input type="hidden" value="${applyReason}" id="applyReason"/>
	<input type="hidden" value="${printDetailId}" id="printDetailId"/>
	
    <div class="left_content">
        <div class="imgheader Noprint">
            <p class="info Noprint">姓名:xxx 年龄:35 性别:女</p>
            <p>
                <a class="btn Noprint" id="large">放大</a>
                <a class="btn Noprint" id="small">缩小</a>
            </p>
        </div>
        <div class="imgContent">
            <div>
                <div class="oImg" id="oImg">
                  <%--   <ul id="img">
                        <li><img src="${basePath}/static/print/imgs/000077.png"></li>
                        <p class="imgTitle">病案首页</p>
                    </ul> --%>
                </div>
            </div>
        </div>
    </div>
    <div class="mid_content Noprint">

        <p class="mid_content_header">
            打印类型:
            <select>
                <option>-请选择-</option>
                <option>门诊</option>
            </select>
        </p>

        <div class="list">
          <!--   <p id="printType">
                <label class="pos-rel">
                    <input type="checkbox" class="ace">
                    <span class="lbl"></span>
                </label>
                <span>病案首页</span>
                <span style="padding-left:8px;">1</span>
            </p> -->
        </div>

    </div>
    <div class="right_content Noprint">
        <div class="right_content_header">
            <p><button>刷新</button><button>退出</button></p>
            <p><button>打印机</button><button onClick="printPrieview()">打印预览</button></p>
            <p><button style="width:168px" onClick="doPrint('打印...')">打印...</button></p>
            <p><button style="width:168px" onClick="doPrint('打印')">打印</button></p>
            <p><span>当前有1份套打任务请求加载</span></p>
        </div>
        <div class="right_content_content">
            <p class="active">每页单价: <span class="num">0.5</span> 元</p>
            <p><span style="float:left">套打份数:</span>　<input type="text" value="1" onchange="getnum(this)" class="copies"></p>
            <p>打印页数: <span class="num page_num" ></span> </p>
            <p class="active">打印金额: <span class="num price_count"></span></p>
        </div>
    </div>
</div>
<script src="${basePath}/static/print/js/jquery.min.js"></script>
<script src="${basePath}/static/print/js/print.js"></script>
<script >        
   function printWithAlert() {      
   document.all.WebBrowser.ExecWB(6,1);   
   }    
   function printWithoutAlert() {
   PageSetup_Null();     
     document.all.WebBrowser.ExecWB(6,6);    
   }  
  function printSetup() {    
  PageSetup_Null();  
  document.all.WebBrowser.ExecWB(8,1);    
  }   
  function printPrieview() { 
  pagesetup_null();  
  document.all.WebBrowser.ExecWB(7,1);    
  }    
 function printImmediately() {      
 document.all.WebBrowser.ExecWB(6,6);     
  window.close();    
  }    
 
 //设置网页打印的页眉页脚为空 

 var hkey_root,hkey_path,hkey_key; 
 hkey_root="HKEY_CURRENT_USER" 
 hkey_path="\\Software\\Microsoft\\Internet Explorer\\PageSetup\\" 
 //设置网页打印的页眉页脚为空 
 function pagesetup_null(){ 
 	try{ 
 		var RegWsh = new ActiveXObject("WScript.Shell") 
		 hkey_key="header" 
		 RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"") 
		 hkey_key="footer" 
		 RegWsh.RegWrite(hkey_root+hkey_path+hkey_key,"") 
 	}catch(e){
 		
 	} 
 } 
 </script>
<script>
	$(function(){
		var medicalOnlyId=$("#medicalOnlyId").val();
		var applyReason=$("#applyReason").val();
		alert(medicalOnlyId+"--"+applyReason);
		$.ajax({
			type:"post",
			data:{medicalOnlyId:medicalOnlyId,applyReason:applyReason},
			url:"/print/getPrintUrlList",
			dataType:"json",
			async: false,
			success:function(data){
			
				var html="";
				var html1="";
				var index=0;
				for(var i in data){
					var count=countNum(data[i]);
					var printType=i;
					var urls=data[i];
					html1+=" <ul id='img'>";
					for(url in urls){
						index++;
						html1+="<li class='PageNext'><img class='page"+(parseInt(index))+"' src='http://127.0.0.1:8090"+urls[url]+"'></li>"+
                        	"<p class='imgTitle Noprint' style='width:150px'>'"+i+"&nbsp;第"+(parseInt(url)+1)+"页'</p>";
						
                        html+= "<p>"+
						  "<label class='pos-rel'>"+
	                 	  " <input type='checkbox' onchange='query(this)' value='"+(parseInt(index))+"' name='page' checked='checked' class='ace'>"+
	                  	  "<span class='lbl'></span>"+
	              		  "</label>"+
	              	      "<span>"+i+"-0"+(parseInt(url)+1)+"</span>"+
	                      "</p>";
	                      
	                   
					}
					 html1+="</ul>";
					 
				}					
				$(".list").html(html);
				$("#oImg").html(html1);
				
			}
		});
		
		//初始化打印页数和价格
		init();
		
		
		
		
	 	//获取checkbox值
		 function getFormVals(name){
				var arr = [];
				$("input[type='checkbox'][name='"+name+"']:checked").each(function(){
					arr.push($(this).val());	
				});
				return arr.toString();
		}

		/*获取对象、数组的长度、元素个数   *@param obj 要计算长度的元素，可以为object、array、string  */ 
		function countNum(obj){
			var objType = typeof obj;
			if(objType == "string"){
				return obj.length;    
			}else if(objType == "object"){
				var objLen = 0;  
				for(var i in obj){ 
					objLen++;     
				}      
				return objLen;  
			}   
			return false; 
		}
		
	})
	
	 function doPrint(how) {
         	myDoc = {
         		documents: document,
         		
         		copyrights: '杰创软件拥有版权  www.jatools.com'    
         	};
         	if(how == '打印预览...'){
         	
         		document.getElementById("jatoolsPrinter").printPreview(myDoc );   // 打印预览
         	}
           			
          	else if(how == '打印...'){
          	        document.getElementById("jatoolsPrinter").print(myDoc ,true);   // 打印前弹出打印设置对话框
          	}else{ 
          		
          			updatePrintStatus();
          	       // document.getElementById("jatoolsPrinter").print(myDoc ,false);       // 不弹出对话框打印
          	}
        } 
	
	function getnum(obj){
		var $this=$(obj);
		var copies=$this.val();
		var i=getPrintNum();
		var num=$(".page_num").html();
		$(".page_num").html(i*copies);
		$(".price_count").html(i*copies*0.5);
	}
	
	function init(){
		var i=getPrintNum();
 		$(".page_num").html(i);
 		$(".price_count").html(0.5*i);
	}
	
	
	function query(obj){
 		var i=getPrintNum();
 		var copies= $(".copies").val();
 		$(".page_num").html(i*copies);
 		$(".price_count").html(0.5*i*copies);
 		
	}
	
	
	function getPrintNum(){
		var i=0;
		$("input[type='checkbox'][name='page']").each(function(){
 			$(".page"+$(this).val()+"").attr("id","");	
		});
 		$("input[type='checkbox'][name='page']:checked").each(function(){
			i++;
 			$(".page"+$(this).val()+"").attr("id","page"+i+"");	
		});
 		return i;
	}
	
	
	
	function updatePrintStatus(){
		var printDetailId=$("#printDetailId").val();
		$.ajax({
			type:"post",
			data:{printDetailId:printDetailId},
			url:"${basePath}/print/updatePrinting",
			success:function(data){
				
			}
		})
	}
	
</script>
 <!--  <OBJECT  ID="jatoolsPrinter" CLASSID="CLSID:B43D3361-D075-4BE2-87FE-057188254255" 
         codebase="jatoolsPrinter.cab#version=8,6,0,0"></OBJECT>  -->
</body>
</html>









